package com.jrfid.smartcabinet.demo.utils

import com.blankj.utilcode.util.SPUtils
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.jrfid.smartcabinet.demo.model.CabinetConfigInfoModel

object Config {

    fun getCabinetList(): MutableList<CabinetConfigInfoModel> {
        val result: MutableList<CabinetConfigInfoModel> = mutableListOf()
        val json = SPUtils.getInstance().getString("cabinetList", "")
        if (json.isEmpty()) {
            return result
        }
        try {
            val list: MutableList<CabinetConfigInfoModel> = Gson().fromJson(json, object : TypeToken<MutableList<CabinetConfigInfoModel>>() {}.type)
            result.addAll(list)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return result
    }

    fun saveCabinetList(list: MutableList<CabinetConfigInfoModel>) {
        val json = Gson().toJson(list)
        SPUtils.getInstance().put("cabinetList", json)
    }

}